<?php
	include("include/init.php");//配置文件

	$user = new sql_class("user");

	$logout = isset($_GET['action']) ? $_GET['action'] : "";
	if($logout == "logout"){//从user传过来的退出数据
		setcookie("user_info",NULL,time()-1000);//清除cookie退出登录
		show_msg("退出成功","index.php");
		exit;
	}

	if($_POST){
		$user_phone = trim($_POST['user_phone']);//清除两边的空白符
		$user_pw = md5($_POST['user_pw']);
		$user_info = $user->select("user_phone = '$user_phone' AND user_pw = '$user_pw'")->getOne();//从数据库中对比用户信息
		
		if(!empty($user_info)){
			$data = array("user_login"=>time());
			$where = "user_id=".$user_info['user_id'];
			$affect_id = $user->update($data,$where);//将时间更新

			if($affect_id){
				setcookie("user_info",json_encode($user_info),time()+3600*24);//将php转换成json数据(cookie中储存不了数组)
				show_msg("登陆成功","user.php");
				exit;
			}
		}
	}
	

	$smarty->display("login.html");



?>